﻿using Api.WDS.Methods;
using Method.DAL;
using Models.operResult;
using Models.VModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Api.WDS.Operate
{
    public class LatestOp
    {
        /// <summary>
        /// 获取用户最新消息集合
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public OperResult<V_NotifyCount> GetUserAllNotify(string token)
        {
            var uid = new GetUidByToken().GetUid(token);
            if (uid is null)
                return OperResult<V_NotifyCount>.Failed("请重新登录");

            var data = new LatestMet().GetUserAllNotify(Convert.ToInt32(uid));
            if (data is null)
                return OperResult<V_NotifyCount>.Succeed(
                    new V_NotifyCount()
                    {
                        LatestCommentsCount = 0,
                        LatestLikesCount = 0,
                        LatestMessageCount = 0
                    });
            return OperResult<V_NotifyCount>.Succeed(data);
        }

        /// <summary>
        /// 获取用户最新点赞集合
        /// </summary>
        /// <returns></returns>
        public OperResult<List<V_LatestLike>> GetUserLatestLike(string token)
        {
            var uid = new GetUidByToken().GetUid(token);
            if (uid is null)
                return OperResult<List<V_LatestLike>>.Failed("请重新登录");

            return OperResult<List<V_LatestLike>>.Succeed(new LatestMet().GetUserLatestLike(Convert.ToInt32(uid)));
        }

        /// <summary>
        /// 清空用户点赞
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public OperResult DelLatestLike(string token)
        {
            var uid = new GetUidByToken().GetUid(token);
            if (uid is null)
                return OperResult.Failed("请重新登录");

            if (new LatestMet().DelLatestLike(Convert.ToInt32(uid)))
                return OperResult.Succeed();
            return OperResult.Failed("服务器错误");
        }

        /// <summary>
        /// 清空用户评论
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public OperResult DelLatestComment(string token)
        {
            var uid = new GetUidByToken().GetUid(token);
            if (uid is null)
                return OperResult.Failed("请重新登录");

            if (new LatestMet().DelLatestComment(Convert.ToInt32(uid)))
                return OperResult.Succeed();
            return OperResult.Failed("服务器错误");
        }

        /// <summary>
        /// 清空用户消息
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public OperResult DelLatestMessage(string token)
        {
            var uid = new GetUidByToken().GetUid(token);
            if (uid is null)
                return OperResult.Failed("请重新登录");

            if (new LatestMet().DelLatestMessage(Convert.ToInt32(uid)))
                return OperResult.Succeed();
            return OperResult.Failed("服务器错误");
        }
    }
}
